package com.pbc.gmp.action;

import com.pbc.gmp.commons.base.BaseController;
import com.pbc.gmp.commons.utils.PageInfo;
import com.pbc.gmp.commons.utils.StringUtils;
import com.pbc.gmp.model.LoginUserInfo;
import com.pbc.gmp.model.basemodel.Equipmentdetail;
import com.pbc.gmp.model.selectModelVo.EquipmentdetailWhere;
import com.pbc.gmp.model.selectModelVo.selectUserVo;
import com.pbc.gmp.service.IEquipmentdetailService;
import com.pbc.gmp.service.impl.EquipmentdetailServiceImpl;
import com.xiaoleilu.hutool.convert.Convert;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *   前端控制器
 * </p>
 *
 * @author kjk
 * @since 2018-06-14
 */
@Controller
@RequestMapping("/equipmentdetail")
public class EquipmentdetailController extends BaseController {
    /**
     * 管理界面
     * @return
     */
    @Autowired
    private IEquipmentdetailService equipmentdetailService;
    @RequestMapping(value="/manager")
    public String manager() {
        return "service/equipment/equipmentManger";
    }
    /**
     * 进入添加人员管理页面
     *
     * @return
     */
    @RequestMapping(value="/addPage")
    public String addPage() {
        return "service/equipment/equipmentAdd";
    }
    @RequestMapping(value="/editPage")
    public String editPage(Model model, @RequestParam String id) {
        Long sid= Convert.toLong(id);
        Equipmentdetail equipmentdetail= equipmentdetailService.selectById(sid);
        model.addAttribute("equ",equipmentdetail );
        return "service/equipment/equipmentEdit";
    }
    @RequestMapping(value="/equList")
    @ResponseBody
    public Object equimentList(EquipmentdetailWhere equWhere, Integer page, Integer rows, String sort, String order) {
        PageInfo pageInfo = new PageInfo(page, rows, sort, order);
        Map<String, Object> condition = new HashMap<String, Object>();

        if (equWhere.getEqtypeid()!=null) {
            condition.put("eqtypeid", equWhere.getEqtypeid());
        }
        if (equWhere.getEqbrand()!=null) {
            condition.put("eqbrandid", equWhere.getEqbrand());
        }
        if (equWhere.getEqusedepartmentid()!=null) {
            condition.put("equsedepartmentid", equWhere.getEqusedepartmentid());
        }
        if (equWhere.getEqorgid()!=null) {
            condition.put("eqorgid", equWhere.getEqorgid());
        }
        if (equWhere.getEquserid()!=null) {
            condition.put("equserid", equWhere.getEquserid());
        }
        if (equWhere.getEqbuydateStart()!=null) {
            condition.put("eqbuydateStart", equWhere.getEqbuydateStart());
        }
        if (equWhere.getEqbuydateEnd()!=null) {
            condition.put("eqbuydateEnd", equWhere.getEqbuydateEnd());
        }
        if (equWhere.getEquseddateStart()!=null) {
            condition.put("equseddateStart", equWhere.getEquseddateStart());
        }
        if (equWhere.getEquseddateEnd()!=null) {
            condition.put("equseddateEnd", equWhere.getEquseddateEnd());
        }
        if (equWhere.getEqsafeguardStart()!=null) {
            condition.put("eqsafeguardStart", equWhere.getEqsafeguardStart());
        }
        if (equWhere.getEqsafeguardEnd()!=null) {
            condition.put("eqsafeguardEnd", equWhere.getEqsafeguardEnd());
        }

        if (equWhere.getEqstate()!=null) {
            condition.put("eqstate", equWhere.getEqstate());
        }

        pageInfo.setCondition(condition);
        equipmentdetailService.selectEquipmentDetailByDetailWhere(pageInfo);
        return pageInfo;
    }

    @RequestMapping("/add")
    @ResponseBody
    public Object add(Equipmentdetail equipmentdetail) {
        equipmentdetailService.insert(equipmentdetail);
        return renderSuccess("编辑成功！");
    }
    /**
     *
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/edit", method = {RequestMethod.POST })
    @ResponseBody
    public Object edit(Equipmentdetail equ) {
        equipmentdetailService.updateById(equ);
        return renderSuccess("更新成功");
    }
    /**
     * 删除设备
     *
     * @param ids
     * @return
     */

    @RequestMapping(value = "/deletePage", method = {RequestMethod.POST })
    @ResponseBody
    public Object delete(String ids) {
        equipmentdetailService.deleteBatchByIds(ids);
        return renderSuccess("删除成功！");
    }



    }
